﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="xbrlesindus_paring", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(XbrlesindusParing))]
    public class XbrlesindusParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IXbrlesindusParing clazz;
        
        public XbrlesindusParingSerializer(IXbrlesindusParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.FyysiliseIsikuKood!=null) {
                Writer.WriteStartElement("fyysilise_isiku_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.FyysiliseIsikuKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Registrikoodid!=null) {
                Writer.WriteStartElement("registrikoodid");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("integer", "http://www.w3.org/2001/XMLSchema", clazz.Registrikoodid.Count);
                for (int x = 0; ((clazz.Registrikoodid != null) 
                            && (x < clazz.Registrikoodid.Count)); x = (x + 1)) {
                    if (clazz.Registrikoodid[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Registrikoodid[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.Esindusliik!=null) {
                Writer.WriteStartElement("esindusliik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Esindusliik))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="fyysilise_isiku_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesindus_paring>fyysilise_isiku_kood");
                }
                clazz.FyysiliseIsikuKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("fyysilise_isiku_kood")).Value;
            }
            if (Reader.LocalName=="registrikoodid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesindus_paring>registrikoodid");
                }
                clazz.Registrikoodid = new System.Collections.Generic.List<System.Decimal?>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("registrikoodid");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesindus_registrikoodid>item");
                        }
                        clazz.Registrikoodid.Add(new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("item")).Value);
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="esindusliik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesindus_paring>esindusliik");
                }
                clazz.Esindusliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("esindusliik")).Value;
            }
        }
    }
}
